//UI初始化
layui.use(['element', 'form', 'table'], function () {
    var table = layui.table;
    $("#searchBtn").on("click", function () {
        table.reload('page', {
            where: {
                title: $("#title").val()
            }
        })
    });
    $("#createPageBtn").on("click", function () {
        newTab("/page/edit", "页面设计");
    });
    table.render({
        elem: '#page'
        , url: '/page/query'
        , cols: [[
            {field: 'id', title: 'ID', sort: true}
            , {field: 'title', title: '标题'}
            , {field: 'entityIdCN', title: '实体名'}
            /*, {field: 'template', title: '模板'}
            , {field: 'displayMode', title: '显示模式'}
            , {field: 'width', title: '页面宽度'}
            , {field: 'height', title: '页面高度'}*/
            , {title: '操作', toolbar: '#rowBar'}
        ]]
        , response: {
            statusCode: 1 //规定成功的状态码，默认：0
            , dataName: 'rows' //规定数据列表的字段名称，默认：data
        }
        , page: true
    });
    //监听工具条
    table.on('tool(page)', function (obj) {
        var data = obj.data;
        if (obj.event === 'del') {
            layer.confirm('确定删除吗?', function (index) {
                $.ajax({
                    url: "/page/del",
                    dataType: "json",
                    method: "POST",
                    data: {
                        id: data.id
                    },
                    success: function (result) {
                        layui.use('layer', function () {
                            var layer = layui.layer;
                            layer.msg(result.msg);
                            $("#searchBtn").click();
                        });
                    }
                });
                layer.close(index);
            });
        } else if (obj.event === 'edit') {
            newTab("/page/edit?id=" + data.id, "页面设计-" + data.id);
        }
    });
});
